package sbc.group1.lab1.mozartspaces;

import java.awt.Color;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;

import org.mozartspaces.core.Entry;
import org.mozartspaces.core.MzsCoreException;

import sbc.group1.lab1.common.CarBody;
import sbc.group1.lab1.common.Engine;
import sbc.group1.lab1.common.Producer;
import sbc.group1.lab1.common.Wheel;

public class BunchProduce {
    
    private final Space space;
    private final Producer producer;
    
    public static void main(String args[]) throws MalformedURLException, MzsCoreException, URISyntaxException {
        SpaceClient space = new SpaceClient();;
        try {
            space.init(new File(args[0]).toURI().toURL(), new URI(args[1]));
            new BunchProduce(space).run();
        }finally {
            space.getCore().shutdown(false);
        }
    }
    
    public BunchProduce(Space space) {
        this.space = space;
        this.producer = new Producer() {
            @Override
            public int getId() {
                return 1;
            }
        };
    }
    
    public void run() {
        ArrayList<Entry> wheels = new ArrayList<Entry>(8000);
        ArrayList<Entry> carBodies = new ArrayList<Entry>(2000);
        ArrayList<Entry> engines = new ArrayList<Entry>(2000);
        
        for (int i=0; i<2000; i++) {
            carBodies.add(new Entry(new CarBody(producer, false), 
                    ColorCoordinator.newCoordinationData((Color)null)));
            engines.add(new Entry(new Engine(producer, Engine.Type.T100KW, false)));
            wheels.add(new Entry(new Wheel(producer, false)));
            wheels.add(new Entry(new Wheel(producer, false)));
            wheels.add(new Entry(new Wheel(producer, false)));
            wheels.add(new Entry(new Wheel(producer, false)));
        }
        try {
            space.getCapi().write(carBodies, space.getCarBodyContainer());
            space.getCapi().write(engines, space.getEngineContainer());
            space.getCapi().write(wheels, space.getWheelContainer());
            
        } catch (MzsCoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
}
